<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>7_2_3-3-watch监听</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <div id="Application">a：{{a.data}}，b：{{b}}</div>
  <script>
    const App = Vue.createApp({
      setup() {
        let = a = Vue.reactive({
          data: 0,
        });
        let b = Vue.ref(0);
        Vue.watch(
          () => {
            //监听a对象的data属性变化
            return a.data;
          },

          (value, old) => {
            //新值和旧值都可以获取到
            console.log(value, old);
          }
        );
        a.data = 1;

        //可以直接监听ref对象
        Vue.watch(b, (value, old) => {
          //新值和旧值都能获取到
          console.log(value, old);
        });
        b.value = 3;
        return { a, b };
      },
    });
    App.mount("#Application");
  </script>
</body>

</html>